package cn.jk.config;
import cn.jk.bean.MyBean;
import cn.jk.dao.AnimalDao;
import cn.jk.dao.IUserDao;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;
import org.springframework.context.annotation.aspectj.EnableSpringConfigured;
import org.springframework.core.env.Environment;
import org.springframework.instrument.classloading.LoadTimeWeaver;
import org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver;
import org.springframework.stereotype.Controller;

/**
 * nameGenerator bean 名称生成过滤器
 * scopeResolver bean scope处理器
 * EnableLoadTimeWeaving 类加载植入切面
 * EnableAspectJAutoProxy注解：
 * proxyTargetClass true为cglib代理false为jdk代理
 * exposeProxy为可代理内部方法
 *
 * Configurable
 * EnableSpringConfigured   -javaagent:C:\Users\joker\.m2\repository\org\aspectj\aspectjweaver\1.9.2\aspectjweaver-1.9.2.jar
 *
 * EnableLoadTimeWeaving   -javaagent:C:\Users\joker\.m2\repository\org\springframework\spring-instrument\5.2.3.RELEASE\spring-instrument-5.2.3.RELEASE.jar
 *
 * LoadTimeWeavingConfigurer
 */
@Configuration
@EnableSpringConfigured
@EnableAspectJAutoProxy(proxyTargetClass = true,exposeProxy = true)
//@Import(MyImportSelector.class)
@EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.AUTODETECT)
@PropertySource("classpath:test.properties")
@ComponentScan(basePackages = "cn.jk")
//@ComponentScan(basePackages = "cn.jk",excludeFilters = @ComponentScan.Filter(Controller.class)
//		,nameGenerator = MyBeanNameGenerator.class,scopeResolver = MyScopeMetaDataResolver.class)
public class Appconfig{

	/***********************************PropertySource参数****************************************/
	@Value("${name}")
	private String name;

	@Value("${age}")
	private Integer age;

	/**
	 * Environment是PropertySource导入的properties对象
	 */
	@Autowired
	private Environment environment;
	/*****************************************************************************/

	@Bean
	AnimalDao animalDao(){
		return new AnimalDao();
	}

	/**
	 * 设置init和destroy方法
	 * 设置scope
	 */
//	@Bean(initMethod = "init",destroyMethod = "destroy")
//	@Bean
//	@Scope("prototype")
	@Description("我的bean注入测试类")
	MyBean myBean(){
		return new MyBean();
	}

	public void testProperties(){
		System.out.println(name + "   " + environment.getProperty("age"));
	}

//	@Override
	public LoadTimeWeaver getLoadTimeWeaver() {
		return new ReflectiveLoadTimeWeaver();
	}
}
